package BaseTest

object Map2Demo {
  def main(args: Array[String]): Unit = {
    var lst = List(1, 2, 3, 4, 5, 6, 7)
    val res_1 = for (i <- lst) yield i + 1
    println(res_1)


    val f = (x: Int) => x * 10 // lambda 函数
    var res_2 = lst.map(f)
    println(res_2)

    val res_3 = lst.map((x: Int) => x * x) // 可以简化为 x => x*x
    println(res_3)

    //    -----------------filter----------------------
    val res_4 = for (i <- lst if i % 2 == 0) yield i
    println(res_4)
    val res_5 = lst.filter((x: Int) => x % 2 != 0)
    println(res_5)

    val res_6 = lst.filter(x => x % 2 == 0).map(x => x * 10) // chain
    println(res_6)
  }
}
